package com.zyf.workflow.test.work.firmware;

import com.zyf.workflow.node.Node;
import com.zyf.workflow.node.WorkNode;
import com.zyf.workflow.test.work.firmware.bean.FirmwareBean;
import com.zyf.workflow.test.work.firmware.worker.FirmwareUpgradeWorker;
import com.zyf.workflow.work.AbstractWork;
import com.zyf.workflow.work.bean.WorkTypeEnum;
import com.zyf.workflow.worker.Worker;

import java.util.ArrayList;
import java.util.List;

public class CheckResourceStateWork<T> extends AbstractWork<FirmwareBean> {

    public CheckResourceStateWork(FirmwareBean data, String workName) {
        super(data, workName);
    }

    @Override
    public WorkTypeEnum getWorkType() {
        return WorkTypeEnum.DECISION;
    }

    private Node<String> getCheckResourceNode(FirmwareBean firmwareBean) {

        FirmwareUpgradeWorker firmwareUpgradeWorker = new FirmwareUpgradeWorker();
        Worker<FirmwareBean, String, String> worker = firmwareUpgradeWorker::checkResourceState;

        return new WorkNode.Builder<FirmwareBean, String>()
                .withWorker(worker)
                .withNodeId(1)
                .withData(firmwareBean)
                .withName(getWorkName() + "1")
                .setCallBack((data, param) -> {
                    System.out.println("check resource state Finish, callback called");
                    System.out.println(".....");
                })
//                .withType(NodeType.WORK)
                .create();

    }


    @Override
    public List<Node<?>> initNodes(FirmwareBean data) {
        List<Node<?>> nodes = new ArrayList<>();
        Node<String> checkResourceNode = getCheckResourceNode(data);
        nodes.add(checkResourceNode);

        return nodes;
    }

}
